/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aic.security;

import aic.misc.DebugPrint;
import java.io.IOException;
import java.io.InvalidObjectException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;

public class ServerPasswordCallbackHandler implements CallbackHandler {

    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        DebugPrint.println("Entering handle..");

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        DebugPrint.println("Checking the user..");
        if (pc.getIdentifier().equals("joe")) {
            DebugPrint.println("Identifier equals 'joe'");
//            // set the password on the callback. This will be compared to the
//            // password which was sent from the client.
//            pc.setPassword("password");


            if (!pc.getPassword().equals("password")) {
                throw new IOException("Wrong password");
}
        } else {
            DebugPrint.println("Identifier NOT equals 'joe'");
            throw new InvalidObjectException("Invalid identifier");
        }
    }

}
